<?php

namespace App\Admin\Controllers;

use App\Admin\Actions\AuditApplyStore;
use App\Admin\Repositories\TongUserApplyStore;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class TongUserApplyStoreController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new TongUserApplyStore(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->model()->orderBy('id', 'desc');
            $grid->column('name','店铺名称');
            $grid->column('status','审核状态')->display(function($value){
                if($value==1){
                    return '<span style="color: orange">待审核</span>';
                }elseif ($value==2){
                    return '<span style="color: seagreen">审核通过</span>';
                }elseif ($value==3){
                    return '<span style="color: red">审核拒绝</span>';
                }
            });
            $grid->column('u_id','会员编号');
            $grid->column('created_at','申请时间');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->panel();
                $filter->equal('id')->width(3);
                $filter->equal('u_id','会员编号')->width(3);
                $filter->equal('status','审核状态')->select([1=>'待审核',2=>'审核通过',3=>'审核拒绝'])->width(3);

            });

            $grid->actions(function (Grid\Displayers\Actions $actions) {
                $actions->disableDelete();
                $actions->disableEdit();
//                $actions->disableQuickEdit();
//                $actions->disableView();
            });
            $grid->toolsWithOutline(false);

            // 禁用添加按钮
            $grid->disableCreateButton();
            //禁用复选框
            $grid->disableRowSelector();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new TongUserApplyStore(), function (Show $show) {
            $show->row(function (Show\Row $show) {
                $show->width(4)->field('status','状态')->using([1 => '待审核', 2 => '审核通过',3=>'审核拒绝'])
                    ->dot(
                        [
                            1 => 'primary',
                            2 => 'success',
                            3 => 'danger',
                        ],
                        'primary' // 第二个参数为默认值
                    );
                $show->width(5)->field('name','店铺名称');
                $show->width(3)->field('u_id','用户id');
            });
            $show->row(function (Show\Row $show) {
                $show->width(5)->field('created_at','');
                $show->width(5)->field('updated_at','创建时间');
            });

            $show->row(function (Show\Row $show) {
                $show->width(5)->field('id_card_front_img')->image();
                $show->width(5)->field('id_card_op_img')->image();
            });
            $show->row(function (Show\Row $show) {
                $show->width(12)->other_img->explode(',')->view('admin.applyStore.fields.other_img');
            });

            $show->panel()
                ->tools(function ($tools) {
                    $tools->disableEdit();

                    $tools->disableDelete();
                    // 显示快捷编辑按钮
                });
            if($show->model()->status==1){
//                $show->tools('<a class="btn btn-sm btn-default">发货</a>');
                $show->tools(AuditApplyStore::make()->payload(['id'=>$show->model()->id]));
            }

//            $show->field('id');
//            $show->field('name');
//            $show->field('u_id');
//            $show->field('business_img');
//            $show->field('door_img');
//            $show->field('room_img');
//            $show->field('other_img');
//            $show->field('id_card_front_img');
//            $show->field('id_card_op_img');
//            $show->field('status');
//            $show->field('status_desc');
//            $show->field('created_at');
//            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new TongUserApplyStore(), function (Form $form) {
            $form->display('id');
            $form->text('name');
            $form->text('u_id');
            $form->text('business_img');
            $form->text('door_img');
            $form->text('room_img');
            $form->text('other_img');
            $form->text('id_card_front_img');
            $form->text('id_card_op_img');
            $form->text('status');
            $form->text('status_desc');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
